package com.zhuiYun.project.api.syslog.mapper;

import com.zhuiYun.project.api.syslog.entity.SysLog;
import com.zhuiYun.project.api.syslog.model.SysLogModel;
import com.zhuiYun.project.common.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface SysLogMapper extends BaseMapper<SysLog> {


    @Select(" <script> select * from sys_log where  1=1 " + " <when test = 'sysLogModel.userName != &quot;&quot;  and sysLogModel.userName != null'> and user_name like '%${sysLogModel.userName}%'</when>" + " <when test = 'sysLogModel.modular != &quot;&quot;  and sysLogModel.modular != null'> and modular like '%${sysLogModel.modular}%'</when>" + " <when test = 'sysLogModel.startTime != &quot;&quot;  and  sysLogModel.startTime != null' > and create_time &gt; '${sysLogModel.startTime}'</when>" + " <when test = 'sysLogModel.endTime != &quot;&quot;   and  sysLogModel.endTime != null'> and create_time  &lt; '${sysLogModel.endTime}'</when>" + "  order by create_time desc </script>")
    List<SysLogModel> selectSysLogByPage(@Param("sysLogModel") SysLogModel sysLogModel);

    @Select(" <script> select count(1) as count from sys_log where  1=1 "  + " <when test = 'startTime != &quot;&quot;  and  startTime != null' > and create_time &gt;= '${startTime}'</when>" + " <when test = 'endTime != &quot;&quot;   and  endTime != null'> and create_time &lt;= '${endTime}'</when>" + " </script>")
    Integer selectSysLog(@Param("startTime") String startTime, @Param("endTime")String endTime);

    @Select(" <script> select user_name,count(1) as count from sys_log where  1=1 "  + " <when test = 'startTime != &quot;&quot;  and  startTime != null' > and create_time &gt;= '${startTime}'</when>" + " <when test = 'endTime != &quot;&quot;   and  endTime != null'> and create_time &lt;= '${endTime}'</when>" + "  group by user_name order by count desc </script>")
    List<Map<String,Object>> selectUserOperate(@Param("startTime") String startTime, @Param("endTime")String endTime);

    @Select(" <script> select user_name,ip,count(1) as count from sys_log where  1=1 "  + " <when test = 'startTime != &quot;&quot;  and  startTime != null' > and create_time &gt;= '${startTime}'</when>" + " <when test = 'endTime != &quot;&quot;   and  endTime != null'> and create_time &lt;= '${endTime}'</when>" + "  group by user_name,ip order by user_name </script>")
    List<Map<String,Object>> getLoginIpCount(@Param("startTime") String startTime, @Param("endTime")String endTime);
}

